﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/view.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="Workflow.Model" %>
<%@ Import Namespace="Workflow.Model.Enum" %>
<%@ Import Namespace="Workflow.Resource" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   <script type="text/javascript">

       function tiffedit(id) {
           window.open("/tiff/ViewTiffEEM?caseNo=" + id, "_blank", "fullscreen");
       }

       $(function () {
           $('#FolderLevelA').combobox({ url: '<%= Url.Action("GetFolderLevel","GPEEM",new{id=2})%>',
               valueField: 'FolderCode',
               textField: 'FolderName',
               onSelect: function (node) {
                   // alert(node.FolderCode);
                   $('#FolderLevelB').combobox({
                       disabled: false,
                       url: '/MSDEEM/GetClassA?id=' + node.FolderCode,
                       valueField: 'FolderCode',
                       textField: 'FolderName'
                   });
               }
           });
       });
       function Search() {
           var queryParams = $('#tt').datagrid('options').queryParams;

           queryParams.FolderLevelA = $('#FolderLevelA').combobox('getValue');
           queryParams.FolderLevelB = $('#FolderLevelB').combobox('getValue');
           queryParams.WorkStatus = $('#WorkStatus').combobox('getValue');
           queryParams.FileName = $('#FileName').val();
           queryParams.InvoiceNo = $('#InvoiceNo').val();
           queryParams.ReceiveDateFrom = $('#ReceiveDateFrom').datebox('getValue');
           queryParams.ReceiveDateTo = $('#ReceiveDateTo').datebox('getValue');
           queryParams.CheckType = $('#CheckType').combobox('getValue');
           queryParams.OperatorID = $('#OperatorID').combobox('getValue');
           queryParams.StatusOperatorID = $('#StatusOperatorID').combobox('getValue');
           queryParams.StatusDateFrom = $('#StatusDateFrom').datebox('getValue');
           queryParams.StatusDateTo = $('#StatusDateTo').datebox('getValue');
           queryParams.Payment = $('#Payment').combobox('getValue');
           queryParams.Reason = $('#Reason').combobox('getValue');

           $('#tt').datagrid('options').queryParams = queryParams;
           $("#tt").datagrid('reload');
       }
       $(function () {

           $('#WorkStatus').combobox('setValue', '1');

           var queryParams = $('#tt').datagrid('options').queryParams;

           queryParams.WorkStatus = $('#WorkStatus').combobox('getValue');


           $('#tt').datagrid({
               title: '<%=Global.Inquiry %>',

               width: 700,
               height: 600,
               fit: true,
               remoteSort: true,
               singleSelect: false,
               idField: 'CaseNo',
               url: '<%= Url.Action("GetData","GPEEM" )%>',
               fitColumns: true,
               striped: true,
               pageSize: 20,
               pageList: [10, 20, 30, 50],
               queryParams: queryParams,

               columns: [[
					{ field: 'ck', checkbox: true },
                    { field: 'CaseNo', title: '<%=Global.CaseNo %>', sortable: 'true', width: 50 },
                      { field: 'BatchNo', title: '<%=Global.BatchNo %>', sortable: 'true', width: 40 },
					{ field: 'InvoiceNo', title: '<%=Global.InvoiceNoEEM %>', sortable: 'true', width: 95 },
					{ field: 'FileName', title: '<%=Global.FileName %>', sortable: 'true', width: 115 
                    ,formatter: function (value, row, index) {
                    var s = '<a href="#" class="tooltips" style="text-decoration:none;color:blue" onclick="tiffedit(' + row.CaseNo + ')" >' + row.FileName + ' </a> ';
                    return s;
                        }
                     },
					{ field: 'FolderLevelA', combobox: true, title: '<%=Global.FolderLevelA %>', width: 60, sortable: 'true', align: 'right' },
                       { field: 'FolderLevelB', combobox: true, title: '<%=Global.FolderLevelB %>', width: 90, sortable: 'true', align: 'right' },
					{ field: 'CheckType', title: '<%=Global.CheckType %>', sortable: 'true', width: 80, align: 'right' },
                     { field: 'ReceiveDate', title: '<%=Global.ReceiveDate %>', width: 65, sortable: 'true', align: 'center' },
                    { field: 'WorkStatus', title: '<%=Global.WorkStatus %>', width: 60, sortable: 'true', align: 'center' },
                    { field: 'StatusDate', title: '<%=Global.StatusDate %>', width: 110, sortable: 'true', align: 'center' },
                   { field: 'Payment', title: '<%=Global.PaymentEEM %>', width: 60, sortable: true, align: 'center' },
                   
                   { field: 'StatusOperator', title: '<%=Global.StatusOperatorEEM %>', width: 60, sortable: 'false', align: 'center' },
                   { field: 'CommentCode', title: '<%=Global.ReasonTitle %>', width: 95, sortable: 'false', align: 'center' },
                    { field: 'Operator', title: '<%=Global.OperatorEEM %>', width: 60, sortable: 'true', align: 'center' }
               //                      
               //					{ field: 'action', title: 'Action', width: 70, align: 'center',
               //					    formatter: function (value, row, index) {
               //					        if (row.editing) {
               //					            var s = '<a href="#" onclick="saverow(' + index + ')">Save</a> ';
               //					            var c = '<a href="#" onclick="cancelrow(' + index + ')">Cancel</a>';
               //					            return s + c;
               //					        } else {
               //					            var e = '<a href="#" onclick="editrow(' + index + ')">Edit</a> ';
               //					            var d = '<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true"  onclick="deleterow(' + index + ')">Delete</a>';
               //					            return e + d;
               //					        }
               //					    }
               //					}
				]],
               sortName: 'CaseNo',
               sortOrder: 'asc'
           });
       });




       function updateActions() {
           var rowcount = $('#tt').datagrid('getRows').length;
           for (var i = 0; i < rowcount; i++) {
               $('#tt').datagrid('updateRow', {
                   index: i,
                   row: { action: '' }
               });
           }
       }


       function editrow(index) {
           $('#tt').datagrid('beginEdit', index);
       }

       function getallselected() {
           var ids = [];
           var rows = $('#tt').datagrid('getSelections');
           for (var i = 0; i < rows.length; i++) {
               ids.push(rows[i].CaseNo);
           }
           alert(ids.join('\n'));

       }
       function deleterow(index) {

           $.messager.confirm('Confirm', 'Are you sure?', function (r) {
               if (r) {
                   $('#tt').datagrid('deleteRow', index);
                   updateActions();
               }
           });
       }

       function tooltips(value) {
           s = true;
           $.messager.alert('Comment', value);


       }
       var s = false;
       function unselect(index) {
           $('#tt').datagrid('unselectRow', index);

       }

       function saverow(index) {
           $('#tt').datagrid('endEdit', index);
       }
       function cancelrow(index) {
           $('#tt').datagrid('cancelEdit', index);
       }
       function insert() {
           var row = $('#tt').datagrid('getSelected');
           if (row) {
               var index = $('#tt').datagrid('getRowIndex', row);
           } else {
               index = 0;
           }
           $('#tt').datagrid('insertRow', {
               index: index,
               row: {
                   status: 'P'
               }
           });
           $('#tt').datagrid('selectRow', index);
           $('#tt').datagrid('beginEdit', index);
       }
       function openoperator(type) {
           if (type == "1") {
               $('#operator').window('open');
           }
           else {
               $('#operatorAll').window('open');
           }
       }

       function Distribute() {

           var userid = $('#userList').val();

           var ids = [];
           var rows = $('#tt').datagrid('getSelections');
           for (var i = 0; i < rows.length; i++) {
               ids.push(rows[i].CaseNo);
           }

           $('#operator').window('close');

           $('#tt').datagrid('clearSelections');

           if (userid == null) {

               $.messager.alert('<%=Global.ErrorTitle %>', '<%=Global.PleaseSelectUser %>', 'error');
               return false;
           }
           if (ids.length == 0) {
               $.messager.alert('<%=Global.ErrorTitle %>', '<%=Global.pleasecheckdata %>', 'error');
               return false;
           }
           $('#form').form('submit', {
               url: '/GPEEM/DistributeCase?user=' + userid + '&caseNos=' + ids.join(','),
               success: function (data) {
                   eval('data=' + data);
                   if (data.Success) {
                       // _user_form.form('clear');
                       $.messager.alert('<%=Global.InfoTitle %>', data.Message, 'info');
                   } else {
                       $.messager.alert('<%=Global.ErrorTitle %>', data.Message, 'error');
                   }
                   // window.location = '/User/Index';
                   $("#tt").datagrid('reload');
               },
               onSubmit: function () {
                   //if (_user_form.valid())

                   return true;
                   // else
                   //    return false;
               }
           });
       }
       function DistributeAll() {

           var userid = $('#userListAll').val();

           var FolderLevelA = $('#FolderLevelA').combobox('getValue');
           var FolderLevelB = $('#FolderLevelB').combobox('getValue');
           var CheckType = $('#CheckType').combobox('getValue');
           var WorkStatus = $('#WorkStatus').combobox('getValue');
           var FileName = $('#FileName').val();
           var InvoiceNo = $('#InvoiceNo').val();
           var ReceiveDateFrom = $('#ReceiveDateFrom').datebox('getValue');
           var ReceiveDateTo = $('#ReceiveDateTo').datebox('getValue');
           var OperatorID = $('#OperatorID').combobox('getValue');
           var StatusOperatorID = $('#StatusOperatorID').combobox('getValue');
           var StatusDateFrom = $('#StatusDateFrom').datebox('getValue');
           var StatusDateTo = $('#StatusDateTo').datebox('getValue');
           var Payment = $('#Payment').combobox('getValue');
           var Reason = $('#Reason').combobox('getValue');

           var querydata = "&FolderLevelA=" + FolderLevelA;
           querydata = querydata + "&WorkStatus=" + WorkStatus;
           querydata = querydata + "&FileName=" + FileName;
           querydata = querydata + "&InvoiceNo=" + InvoiceNo;
           querydata = querydata + "&ReceiveDateFrom=" + ReceiveDateFrom;
           querydata = querydata + "&ReceiveDateTo=" + ReceiveDateTo;
           querydata = querydata + "&OperatorID=" + OperatorID;
           querydata = querydata + "&FolderLevelB=" + FolderLevelB;
           querydata = querydata + "&CheckType=" + CheckType;
           querydata = querydata + "&StatusOperatorID=" + StatusOperatorID;
           querydata = querydata + "&StatusDateFrom=" + StatusDateFrom;
           querydata = querydata + "&StatusDateTo=" + StatusDateTo;
           querydata = querydata + "&Payment=" + Payment;
           querydata = querydata + "&Reason=" + Reason;

           $('#operatorAll').window('close');
           if (userid == null) {

               $.messager.alert('<%=Global.ErrorTitle %>', '<%=Global.PleaseSelectUser %>', 'error');
               return false;
           }
           $('#form').form('submit', {
               url: '/GPEEM/DistributeCaseAll?user=' + userid + querydata,
               success: function (data) {
                   eval('data=' + data);
                   if (data.Success) {
                       // _user_form.form('clear');
                       $.messager.alert('<%=Global.InfoTitle %>', data.Message, 'info');
                   } else {
                       $.messager.alert('<%=Global.ErrorTitle %>', data.Message, 'error');
                   }
                   // window.location = '/User/Index';
                   $("#tt").datagrid('reload');
               },
               onSubmit: function () {
                   //if (_user_form.valid())

                   return true;
                   // else
                   //    return false;
               }
           });

       }

       function PickUp() {

           var ids = [];
           var rows = $('#tt').datagrid('getSelections');
           for (var i = 0; i < rows.length; i++) {
               ids.push(rows[i].CaseNo);

           }
           $('#tt').datagrid('clearSelections');

           if (ids.length == 0) {
               $.messager.alert('<%=Global.ErrorTitle %>', '<%=Global.pleasecheckdata %>!', 'error');
               return false;
           }
           $('#form').form('submit', {
               url: '/GPEEM/PickUpCase?caseNos=' + ids.join(','),
               success: function (data) {
                   eval('data=' + data);
                   if (data.Success) {
                       // _user_form.form('clear');
                       $.messager.alert('<%=Global.InfoTitle %>', data.Message, 'info');
                   } else {
                       $.messager.alert('<%=Global.ErrorTitle %>', data.Message, 'error');
                   }


                   // window.location = '/User/Index';
                   $("#tt").datagrid('reload');
               },
               onSubmit: function () {
                   //if (_user_form.valid())

                   return true;
                   // else
                   //    return false;
               }
           });

       }
       function PickUpAll() {
           var FolderLevelA = $('#FolderLevelA').combobox('getValue');
           var FolderLevelB = $('#FolderLevelB').combobox('getValue');
           var CheckType = $('#CheckType').combobox('getValue');
           var WorkStatus = $('#WorkStatus').combobox('getValue');
           var FileName = $('#FileName').val();
           var InvoiceNo = $('#InvoiceNo').val();
           var ReceiveDateFrom = $('#ReceiveDateFrom').datebox('getValue');
           var ReceiveDateTo = $('#ReceiveDateTo').datebox('getValue');
           var OperatorID = $('#OperatorID').combobox('getValue');
           var StatusOperatorID = $('#StatusOperatorID').combobox('getValue');
           var StatusDateFrom = $('#StatusDateFrom').datebox('getValue');
           var StatusDateTo = $('#StatusDateTo').datebox('getValue');
           var Payment = $('#Payment').combobox('getValue');
           var Reason = $('#Reason').combobox('getValue');

           var querydata = "&FolderLevelA=" + FolderLevelA;
           querydata = querydata + "&WorkStatus=" + WorkStatus;
           querydata = querydata + "&FileName=" + FileName;
           querydata = querydata + "&InvoiceNo=" + InvoiceNo;
           querydata = querydata + "&ReceiveDateFrom=" + ReceiveDateFrom;
           querydata = querydata + "&ReceiveDateTo=" + ReceiveDateTo;
           querydata = querydata + "&OperatorID=" + OperatorID;
           querydata = querydata + "&FolderLevelB=" + FolderLevelB;
           querydata = querydata + "&CheckType=" + CheckType;
           querydata = querydata + "&StatusOperatorID=" + StatusOperatorID;
           querydata = querydata + "&StatusDateFrom=" + StatusDateFrom;
           querydata = querydata + "&StatusDateTo=" + StatusDateTo;
           querydata = querydata + "&Payment=" + Payment;
           querydata = querydata + "&Reason=" + Reason;

           $('#form').form('submit', {
               url: '/GPEEM/PickUpCaseAll?' + querydata,
               success: function (data) {
                   eval('data=' + data);
                   if (data.Success) {
                       $.messager.alert('<%=Global.InfoTitle %>', data.Message, 'info');
                   } else {
                       $.messager.alert('<%=Global.ErrorTitle %>', data.Message, 'error');
                   }

               },
               onSubmit: function () {
                   //if (_user_form.valid())

                   return true;
                   // else
                   //    return false;
               }
           });

       }
       function Export() {
           var FolderLevelA = $('#FolderLevelA').combobox('getValue');
           var FolderLevelB = $('#FolderLevelB').combobox('getValue');
           var CheckType = $('#CheckType').combobox('getValue');
           var WorkStatus = $('#WorkStatus').combobox('getValue');
           var FileName = $('#FileName').val();
           var InvoiceNo = $('#InvoiceNo').val();
           var ReceiveDateFrom = $('#ReceiveDateFrom').datebox('getValue');
           var ReceiveDateTo = $('#ReceiveDateTo').datebox('getValue');
           var OperatorID = $('#OperatorID').combobox('getValue');
           var StatusOperatorID = $('#StatusOperatorID').combobox('getValue');
           var StatusDateFrom = $('#StatusDateFrom').datebox('getValue');
           var StatusDateTo = $('#StatusDateTo').datebox('getValue');
           var Payment = $('#Payment').combobox('getValue');
           var Reason = $('#Reason').combobox('getValue');

           var querydata = "&FolderLevelA=" + FolderLevelA;
           querydata = querydata + "&WorkStatus=" + WorkStatus;
           querydata = querydata + "&FileName=" + FileName;
           querydata = querydata + "&InvoiceNo=" + InvoiceNo;
           querydata = querydata + "&ReceiveDateFrom=" + ReceiveDateFrom;
           querydata = querydata + "&ReceiveDateTo=" + ReceiveDateTo;
           querydata = querydata + "&OperatorID=" + OperatorID;
           querydata = querydata + "&FolderLevelB=" + FolderLevelB;
           querydata = querydata + "&CheckType=" + CheckType;
           querydata = querydata + "&StatusOperatorID=" + StatusOperatorID;
           querydata = querydata + "&StatusDateFrom=" + StatusDateFrom;
           querydata = querydata + "&StatusDateTo=" + StatusDateTo;
           querydata = querydata + "&Payment=" + Payment;
           querydata = querydata + "&Reason=" + Reason;


           $('#form').form('submit', {
               url: '/GPEEM/ExportCase?' + querydata,
               success: function (data) {
                   eval('data=' + data);
                   if (data.Success) {
                       // _user_form.form('clear');
                       //$.messager.alert('<%=Global.InfoTitle %>', data.Message, 'info');
                   } else {
                       $.messager.alert('<%=Global.ErrorTitle %>', data.Message, 'error');
                   }
                   // window.location = '/User/Index';
                   // $("#tt").datagrid('reload');
               },
               onSubmit: function () {
                   //if (_user_form.valid())

                   return true;
                   // else
                   //    return false;
               }
           });

       }
      
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
   <form class="easyui-layout" method="post" id="form" name="form" style=" width:100%;height: 700px;">
       <div region="center" >
    <table id="tt" class="easyui-datagrid" style="width: 600px; height: 250px" idfield="itemid"
        title="Inquiry" iconcls="icon-save" toolbar="#tb" rownumbers="true" pagination="true">
        <div id="tb" style="padding: 5px; height: auto">
            <div style="margin-bottom: 5px">
                <%
                    int rolecode = (int)ViewData["RoleCode"];
                    if (rolecode == (int)EnumRole.GPEEMPL || 
                        rolecode == (int)EnumRole.GPPTPPL || 
                        rolecode == (int)EnumRole.GPAHEEMPL||
                        rolecode == (int)EnumRole.GPAHPTPPL)
                    {
                        Response.Write(" <a href=\"#\" class=\"easyui-linkbutton\" iconcls=\"icon-add\" onclick=\"openoperator('1')\" plain=\"true\">" + Global.Distribute + "</a> ");
                        //Response.Write(" <a href=\"#\" class=\"easyui-linkbutton\" iconcls=\"icon-add\" onclick=\"openoperator('2')\" plain=\"true\">" + Global.DistributeAll + "</a>");
                    }
                    if (rolecode == (int)EnumRole.GPEEMPA || rolecode == (int)EnumRole.GPAHEEMPA)
                    {
                        Response.Write("<a href=\"#\" class=\"easyui-linkbutton\" iconcls=\"icon-edit\"  onclick=\"PickUp()\" plain=\"true\">" + Global.Pickup + "</a>");
                       // Response.Write("<a href=\"#\" class=\"easyui-linkbutton\" iconcls=\"icon-edit\" onclick=\"PickUpAll()\" plain=\"true\">" + Global.PickUpAll + "</a>");
                    }
            
                %>
                

                <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="Search();"><%=Global.Search%></a>

                <a href="#" class="easyui-linkbutton"  iconcls="icon-redo" onclick="Export();"> <%=Global.Export%></a>

                
            </div>
            <div>
              
                <%=Global.dateFrom %>:
                <input id="ReceiveDateFrom" class="easyui-datebox" style="width: 80px">
                <%=Global.dateTo %>:
                <input id="ReceiveDateTo" class="easyui-datebox" style="width: 80px">
                <%=Global.StatusOperatorEEM %>
               <input id="StatusOperatorID" class="easyui-combobox" style="width: 80px" url="/GPEEM/GetUserList"
                    valuefield="UserID" textfield="UserName" editable="false">
                <%=Global.OperatorEEM%>:
                <input id="OperatorID" class="easyui-combobox" style="width: 80px" url="/GPEEM/GetUserList"
                    valuefield="UserID" textfield="UserName" editable="false">
                <%=Global.FileName%>:<input id="FileName" class="txt01" style="width: 120px">
                <%=Global.InvoiceNoEEM%>.:<input id="InvoiceNo" class="txt01" style="width: 100px">
               <%=Global.ReasonTitle%>:<input id="Reason" name="Reason" class="easyui-combobox" style="width: 150px" url="/GPEEM/GetCaseReasonList"
                    valuefield="Id" textfield="JpReason" editable="false">
               
                    <br>
                     <%=Global.FolderLevelA%>:
                <input id="FolderLevelA" class="easyui-combobox" style="width: 100px" valuefield="FolderCode"
                    textfield="FolderName" multiple="false" editable="false">
                     <%=Global.FolderLevelB%>:
                <input id="FolderLevelB" class="easyui-combobox" style="width: 100px" valuefield="FolderCode"
                    textfield="FolderName" multiple="false" editable="false" disabled="true">
                 <%=Global.CheckType%>:
                <input id="CheckType" url="/GPEEM/GetFolderLevel?id=0" class="easyui-combobox" style="width: 100px"
                    valuefield="FolderCode" textfield="FolderName" multiple="false" editable="false">
                     <%=Global.WorkStatus%>:<input id="WorkStatus" class="easyui-combobox" style="width: 110px" url="/GPEEM/GetWorkStutes"
                    valuefield="WorkStatusCode" textfield="WorkStatusNameEEM" editable="false">
                       <%=Global.StatusDate%>:<input class="easyui-datetimebox" id="StatusDateFrom" name="StatusDateFrom"  style="width:135px">
       <input class="easyui-datetimebox" id="StatusDateTo" name="StatusDateTo"  style="width:135px">
        <%=Global.PaymentEEM%>:<input id="Payment" class="easyui-combobox" style="width: 110px" url="/GPEEM/GetPayments"
                    valuefield="PaymentId" textfield="PaymentName" editable="false">

                <br>
               
            </div>
        </div>
        </table>
        </div>
        </form>
        <div id="operator" class="easyui-window" closed="true" modal="true" title=" <%=Global.DistributeTask%>"
            style="width: 300px; height: 100px; padding-top: 15px">
            <%=Global.Operator%>:
            <select id="userList" name="userList" style="width: 100px;">
                <% 
                    foreach (var o in (IList<User>)ViewData["UserList"])
                    {
                        Response.Write("<option value='" + o.UserID + "'>" + o.UserName + "</option> );");
                    }
                %>
            </select>
            <a href="#" class="easyui-linkbutton" onclick="Distribute();"><%=Global.Distribute%>!</a>
        </div>
        <div id="operatorAll" class="easyui-window" closed="true" modal="true" title=" <%=Global.DistributeTask%>"
            style="width: 300px; height: 100px; padding-top: 15px">
            <%=Global.Operator%>:
            <select id="userListAll" name="userListAll" style="width: 100px;">
                <% 
                    foreach (var o in (IList<User>)ViewData["UserList"])
                    {
                        Response.Write("<option value='" + o.UserID + "'>" + o.UserName + "</option> );");
                    }
                %>
            </select>
            <a href="#" class="easyui-linkbutton" onclick="DistributeAll();"><%=Global.Distribute%>!</a>
        </div>
</asp:Content>
